import {fgui} from "../../../../../libs/fairygui.1.3.0";
import View from "../../../../mvc/View";
import Commands from "../constants/Commands";
import ViewNames from "../constants/ViewNames";
import SystemLoadingView from "./SystemLoadingView";
import SystemLoadingVc from "./vc/SystemLoadingVc";
import HomeView from "./HomeView";
import HomeVc from "./vc/HomeVc";
import {loadUi} from "../utils/loadUi";

export default class MainView extends View {

    constructor(name, viewComponent) {
        super(name, viewComponent);
    }

    onRegister() {
        // 注册系统加载视图,用于没有加载进度或较短加载时间的情况
        if (!this.retrieveView(ViewNames.SYS_LOADING)) {
            this.sendEvent(Commands.REGISTER_VIEW, {
                name: ViewNames.SYS_LOADING,
                viewCls: SystemLoadingView,
                vcCls: SystemLoadingVc
            });
        }
        this.sendEvent(Commands.SYS_LOADING_PROGRESS);
        loadUi(
            (progress) => {
                // console.log(progress);
            },
            () => {
                this.sendEvent(Commands.LOADING_COMPLETE);
                this.sendEvent(Commands.REGISTER_VIEW, {
                    name: ViewNames.HOME,
                    viewCls: HomeView,
                    vcCls: HomeVc
                });
            }
        );
    }

    onRemove() {

    }
}